<?php

namespace App\Services;

use App\Models\EstateResources;
use App\Models\Mini\NoticeModel;

class ResourcesService extends BaseService
{
    /**
     * @Notes 获取资源位
     * @return array
     * @author ypp
     * @date 2021/3/5
     * @time 9:42
     */
    public function getResourcesList(): array
    {
        //获取认证用户信息
        $user_info = auth('user')->user();
        $now       = strtotime(date('Y-m-d'));
        $whereRaw = 'find_in_set('.$user_info['community_id'].',community_id)';
        $list = EstateResources::where(['estate_id' => $user_info['property_id'],'is_show'=>1,'status'=>1])
            ->where([['start_time', '<=', $now], ['end_time', '>=', $now]])
            ->whereRaw($whereRaw)
            ->OrWhere(function ($query) use ($user_info) {
                $query->where(['estate_id' => $user_info['property_id']])->where('end_time', 0);
            })->orderBy('create_time', 'desc')->get();

        return $list ? $this->format($list) : $this->format_error('暂无资源位');

    }
}
